class Solution:
    def myAtoi(self, s: str) -> int:
        s = s.lstrip()
        if not s:
            return 0
        i: int = 0
        res: str = ""
        sign: int = 1
        length = len(s)
        if s[0] == "-":
            sign = -1
            i += 1
        elif s[0] == "+":
            sign = 1
            i += 1
        while i < length and s[i].isdigit():
            res += s[i]
            i += 1
        if not res:
            return 0
        if int(res) * sign < -(2**31):
            return -(2**31)
        elif int(res) * sign > 2**31 - 1:
            return 2**31 - 1
        return int(res) * sign


x = " -042"
sol = Solution()
print(sol.myAtoi(x))
